import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt

root = ET.parse("D:\\StarCraft\\bwapi-data\\logs\\g.xml").getroot()
generations = root.findall("generation")

std = [[],[],[],[]]

for gen in generations:
	dev = [0,0,0,0]
	for o in std: o.append(0)
	for g in gen.findall("genome"):
		i = 0
		for o in g.findall("objective"):
			std[i][len(std[i])-1] += float(o.get("fitness"))
			i += 1
	for o in std:
		o[len(o)-1] = o[len(o)-1] / float(len(gen.findall("genome")))
		
	for g in gen.findall("genome"):
		i = 0
		for o in g.findall("objective"):
			dev[i] += abs(float(o.get("fitness")) - std[i][len(std[i])-1])
			i += 1
	for d in range(len(dev)):
		dev[d] = dev[d] / float(len(gen.findall("genome")))
		
	std[0][len(std[0])-1] = dev[0]
	std[1][len(std[1])-1] = dev[1]
	std[2][len(std[2])-1] = dev[2]
	std[3][len(std[3])-1] = dev[3]
	
plt.subplot(221)
plt.ylabel("standard deviation")
plt.title("$fitness_{FF}$")
#plt.axis([0,len(std[0])-1,0,0.02])
plt.plot(std[0])
plt.subplot(222)
plt.title("$fitness_{HP}$")
#plt.axis([0,len(std[0])-1,0.0,0.14])
plt.plot(std[1])
plt.subplot(223)
plt.title("$fitness_{MA}$")
#plt.axis([0,len(std[0])-1,0.015,0.05])
plt.plot(std[2])
plt.subplot(224)
plt.title("$fitness_{KS}$")
#plt.axis([0,len(std[0])-1,0.0,0.14])
plt.plot(std[3])
plt.show()

